<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/06/02
// +----------------------------------------------------------------------

namespace app\erp\model;

use think\Model;

/**
 * 采购单-回款管理
 * @package app\erp\model
 */
class ErpGoodsPurchaseOrderBack extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_erp_goods_purchase_order_back';

    /**
     * 查询数据
     * @param id int 优惠券id
     * @author jason
     * @return array_out(code, message, (int)id)
     */
    public function getInfoById($id, $cache = true){
        $info = $this -> cache($cache) -> find($id);
        if($info){
            return array_out(200, 'success', $info);
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 添加数据
     * @param purchase_id 	            int         采购单ID
     * @param supplier_id 	            int         供货商ID
     * @param supplier_rebate 		    string      供货商返利%
     * @param supplier_bank_account 	int         实际支付银行账号
     * @param purchase_sum_cg 		    decimal     采购单预采购总价
     * @param purchase_sum_rk 		    decimal     采购单入库总价
	 * @param pay_sum 		            decimal     实际回款价格
     * @param pay_time 				    int         实际回款时间
     * @param pay_status 			    tinyint     是否回款(0未回;1已回)
     * @param create_time 				int         创建时间
     * @param update_time 				int         编辑时间
     * @author dou<51779987@qq.com>
     * @return array_out(code, message, (int)id)
     */
    public function addData($purchase_id, $supplier_id, $supplier_rebate, $supplier_bank_account, $purchase_sum_cg, $purchase_sum_rk, $pay_sum, $pay_time, $pay_status=0){
        $data['purchase_id']                = $purchase_id;
        $data['supplier_id']                = $supplier_id;
        $data['supplier_rebate']            = $supplier_rebate;
        $data['supplier_bank_account']      = $supplier_bank_account;
        $data['purchase_sum_cg']            = $purchase_sum_cg;
        $data['purchase_sum_rk']            = $purchase_sum_rk;
        $data['pay_sum']                    = $pay_sum;
        $data['pay_time']                   = $pay_time;
        $data['pay_status']                 = $pay_status;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();
        if($res){
            return array_out(200, 'success', $this->id);
        }else{
            return array_out(-1001, 'error');
        }
    }


    /**
     * 编辑数据
     * @param id 	                    string      主键
     * @param purchase_id 	            int         采购单ID
     * @param supplier_id 	            int         供货商ID
     * @param supplier_rebate 		    string      供货商返利%
     * @param supplier_bank_account 	int         实际支付银行账号
     * @param purchase_sum_cg 		    decimal     采购单预采购总价
     * @param purchase_sum_rk 		    decimal     采购单入库总价
     * @param pay_sum 		            decimal     实际回款价格
     * @param pay_time 				    int         实际回款时间
     * @param pay_status 			    tinyint     是否回款(0未回;1已回)
     * @param create_time 				int         创建时间
     * @param update_time 				int         编辑时间
     * @author dou<51779987@qq.com>
     * @return array_out(code, message, (int)id)
     */
	public function editData($id, $purchase_id, $supplier_id, $supplier_rebate, $supplier_bank_account, $purchase_sum_cg, $purchase_sum_rk,$pay_sum, $pay_time, $pay_status){
		$map = [];
		$map['id'] = $id;
		
		$data = [];
        $data['purchase_id']            = $purchase_id;
        $data['supplier_id']            = $supplier_id;
        $data['supplier_rebate']        = $supplier_rebate;
        $data['supplier_bank_account']  = $supplier_bank_account;
        $data['purchase_sum_cg']            = $purchase_sum_cg;
        $data['purchase_sum_rk']            = $purchase_sum_rk;
        $data['pay_sum']                = $pay_sum;
        $data['pay_time']               = $pay_time;
        $data['pay_status']             = $pay_status;
        $res = $this ->update($data, $map);
		if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/**
     * 删除数据
     * @param int $id
     * @author dou<51779987@qq.com>
     * @return bool
     */
    public function deleteData($id){
        $res = self::destroy($id);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
}
